/**
 * @(#)com.basic.collection.VectorTest
 *
 * Copyright (c) 2014-2018 上海纬视瑞科技有限公司
 *
 * DESC:
 *
 */
package com.basic.collection;

import java.util.*;

/**
 *
 *
 *   去除Vector 重复数据
 * @author fusf
 * @version 1.0  2017/3/14
 */
public class VectorTest {

    public static void main(String[] args) {
        List list = new Vector();
        list.add("a");
        list.add("a");
        list.add("b");
        list.add("b");
        list.add("v");
        list.add("v");
        list.add("va");
        list.add("f");
        //list = method1(list);
        list = method2(list);
        for (Object o : list) {
            System.out.println(o);
        }
    }

    /**
     * 方法一 ，创建新数组，判断是否重复，重复就丢弃
     *
     * @param list
     * @return
     */
    public static List method1(List list) {
        List list_new = new Vector();
        for (Object o : list) {
            if (!list_new.contains(o)) {
                list_new.add(o);
            }
        }
        return list_new;
    }

    /**
     * 方法二 ，创建新的List，根据HashSet过滤
     *
     * @param list
     * @return
     */
    public static List method2(List list) {
        List list_new = new Vector();
        Set set = new HashSet(list);
        Iterator it = set.iterator();
        while (it.hasNext()) {
            list_new.add(it.next());
        }
        return list_new;
    }


}
